﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Admin/Admin.Master" AutoEventWireup="true" CodeBehind="Categories.aspx.cs" Inherits="Cms.Web.UI.Admin.Categories" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
    <link rel="Stylesheet" href="Admin/Css/List.css" type="text/css" />
    <link rel="Stylesheet" href="Admin/Css/DragAndDrop.css" type="text/css" />
    <link rel="Stylesheet" href="Admin/Css/EditMenu.css" type="text/css" />
    <script language="javascript" src="Admin/Js/DragAndDrop.js"></script>
    <script language="javascript">
        //<![CDATA[
        function initList() {
            cms.DnD.ClearDropZones();
            var spans = document.getElementById("categoryPane").getElementsByTagName("span");
            for (var i = 0; i < spans.length; i++) {
                if (spans[i].parentNode.tagName == "DIV") {
                    cms.DnD.AddDropZone(spans[i]);
                    spans[i].parentNode.id = "T" + spans[i].id.substring(1);
                    cms.DnD.AddDropZone(spans[i].parentNode);
                    iLib.Dom.AddListener(spans[i], "mouseover", function (e) {
                        if (cms.DnD.GetIsDragging())
                            return;
                        e = e || window.event;
                        var target = e.target || e.srcElement;
                        while (target.parentNode && target.parentNode.tagName != "DIV")
                            target = target.parentNode;
                        target.className = "hover";
                    });
                    iLib.Dom.AddListener(spans[i], "mouseout", function (e) {
                        if (cms.DnD.GetIsDragging())
                            return;
                        e = e || window.event;
                        var target = e.target || e.srcElement;
                        while (target.parentNode && target.parentNode.tagName != "DIV")
                            target = target.parentNode;
                        target.className = "";
                    });
                    iLib.Dom.AddListener(spans[i], "mousedown", function (e) {
                        cms.DnD.InitDrag("DIV", e);
                    });
                    iLib.Dom.AddListener(spans[i], "click", function (e) {
                        e = e || window.event;
                        var target = e.target || e.srcElement;
                        var baseUrl = window.location.protocol + "//" + window.location.host + "/Admin/";
                        window.location.href = baseUrl + "EditCategory.aspx?id=" + target.parentNode.id.substring(1);
                    });
                }
            }
            var imgs = document.getElementById("categoryPane").getElementsByTagName("img");
            for (var i = 0; i < imgs.length; i++) {
                if (imgs[i].parentNode.tagName == "SPAN") {
                    iLib.Dom.AddListener(imgs[i], "click", function (e) {
                        e = e || window.event;
                        var target = e.target || e.srcElement;
                        iLib.Dom.PreventBubble(e);
                        preparePopup(target, target.parentNode.id, target.nextSibling.textContent, e);
                    });
                }
            }
            cms.DnD.AddStartDragHandler(onStartDrag);
            cms.DnD.AddEndDragHandler(onEndDrag);
        }

        function onEndDrag(draggedElement, dropzoneElement, dropzonePart) {
            document.getElementById("ctl00_body_hidDraggedID").value = draggedElement.id;
            document.getElementById("ctl00_body_hidDropzoneID").value = dropzoneElement != null ? dropzoneElement.id : "";
            document.getElementById("ctl00_body_hidDropzonePart").value = dropzonePart;
            if (dropzoneElement != null && draggedElement.id != dropzoneElement.id) {
                cms.Lists.ShowPaneOverlay("categoryPaneOverlay");
                __doPostBack('ctl00$body$lbDragEnd', '');
            }
        }

        function onStartDrag(e) {
            cms.Lists.HidePopups(e);
        }

        function preparePopup(trigger, id, name, e) {
            var popup = document.getElementById("pnlPopup");
            var hlEdit = document.getElementById("hlEdit");
            hlEdit.href = "Admin/EditCategory.aspx?id=" + id.substring(1);
            document.getElementById("ctl00_body_hidDeleteID").value = id;
            cms.Lists.CurrentName = name;
            cms.Lists.ShowPopup(popup, trigger, "left", 0, 0, true, e);
        }
        //]]>
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="buttons" runat="server">
    <a href="Admin/EditCategory.aspx" class="orangeButton"><span><span><img src="Admin/Img/icons/tag_orange_add.png" alt="" /><span><cms:LocalizedLiteral ID="llNewCategory" runat="server" /></span></span></span></a>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="body" runat="server">
    <asp:Literal ID="litIcon" runat="server" Visible="false" Text="Admin/Img/Icons/tag_orange.png" />
    <div id="categoryPane" style="position: relative;">
        <asp:UpdatePanel ID="upnlCategories" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
            <ContentTemplate>
                <asp:Panel ID="pnlActions" runat="server" />
                <table class="list" id="tblCategories">
                    <tr>
                        <th><cms:LocalizedLiteral ID="llNameHeader" runat="server" /></th>
                        <th><cms:LocalizedLiteral ID="llCategoryIDHeader" runat="server" /></th>
                    </tr>
                    <asp:Repeater ID="rpCategories" runat="server" OnItemDataBound="rpCategories_ItemDataBound">
                        <ItemTemplate>
                            <tr>
                                <td style="padding: 0px;"><asp:Literal ID="litID" runat="server" /><img src="Admin/Img/icons/tag_orange.png" /><span><asp:literal ID="litName" runat="server" /></span><asp:Literal ID="litCloser" runat="server" /></td>
                                <td><asp:Literal ID="litCategoryID" runat="server" /></td>
                            </tr>
                        </ItemTemplate>
                    </asp:Repeater>
                </table>
                <asp:Label ID="lblNoCategories" runat="server"><cms:LocalizedLiteral ID="llNoCategories" runat="server" /></asp:Label>
            </ContentTemplate>
        </asp:UpdatePanel>
        <div id="categoryPaneOverlay" class="paneOverlay"></div>
        <div id="categoryPaneOverlayProgress" class="paneOverlayProgress"><img src="Admin/img/progress.gif" /></div>
    </div>
    <asp:UpdatePanel ID="upnlActions" runat="server" UpdateMode="Conditional" ChildrenAsTriggers="false">
        <ContentTemplate>
            <div id="pnlPopup" class="popup">
                <div class="popupMenuTop">
                    <div class="popupMenuTopBg">&nbsp;</div>
                    <div class="popupMenuTopLeftCorner">&nbsp;</div>
                    <div class="popupMenuTopRightCorner">&nbsp;</div>
                </div>
                <div class="popupMenu">
                    <div class="popupMenuLeftBg">&nbsp;</div>
                    <div class="popupMenuRightBg">&nbsp;</div>
                    <div class="popupMenuContent">
                        <a id="hlEdit" href="#"><img src="Admin/Img/icons/tag_orange_edit.png" /><span><cms:LocalizedLiteral ID="llEdit" runat="server" /></span></a>
                        <div class="horizontalDivider" style="margin-bottom: 3px; margin-top: 4px; margin-left: 27px; margin-right: 4px;"></div>
                        <asp:LinkButton ID="lbDelete" runat="server" OnClick="lbDelete_Click"><img id="imgDelete" runat="server" src="Admin/Img/icons/cross.png" /><span id="lblDelete" runat="server"><cms:LocalizedLiteral ID="llDelete" runat="server" /></span></asp:LinkButton>
                    </div>
                </div>
                <div class="popupMenuBottom">
                    <div class="popupMenuBottomBg">&nbsp;</div>
                    <div class="popupMenuBottomLeftCorner">&nbsp;</div>
                    <div class="popupMenuBottomRightCorner">&nbsp;</div>
                </div>
            </div>
            <input type="hidden" id="hidDeleteID" runat="server" />
            <input type="hidden" id="hidDraggedID" runat="server" />
            <input type="hidden" id="hidDropzoneID" runat="server" />
            <input type="hidden" id="hidDropzonePart" runat="server" />
            <asp:LinkButton ID="lbDragEnd" runat="server" OnClick="lbDragEnd_Click" Text="DragEnd" style="position: absolute; left: -10000px;" />
        </ContentTemplate>
    </asp:UpdatePanel>
    <script language="javascript">
        iLib.Dom.AddListener(window, "load", initList);
        cms.Ajax.Init();
        cms.Ajax.AddEndRequestHandler(cms.Lists.HidePaneOverlays);
    </script>
</asp:Content>
